package com.example.leetcode.trainingcamp.week2.practice;

import java.util.HashSet;
import java.util.Set;

public class Test160 {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode preA = headA;
        ListNode preB = headB;
        Set<ListNode> list = new HashSet<>();
        while (preA != null){
            list.add(preA);
            preA = preA.next;
        }
        while (preB != null){
            if (list.contains(preB)){
                return preB;
            }else {
                preB = preB.next;
            }
        }
        return null;
    }
}
